//
//  StatusCell.swift
//  新浪微博
//
//  Created by yzl on 15/8/3.
//  Copyright © 2015年 yjc. All rights reserved.
//

import UIKit

class StatusCell: UITableViewCell {
/// 微博数据模型
    var Wstatus: Status? {
        didSet {
        topview.status = Wstatus
        contentLabel.text = Wstatus?.text ?? ""
            // 设置配图视图数据
            pictureView.status = Wstatus
          // 设置配图视图尺寸
            pictureWidthCons?.constant = pictureView.bounds.size.width
            pictureHeightCons?.constant = pictureView.bounds.size.height
        }
    }
    /// 设置 图片宽度约束
    var pictureWidthCons: NSLayoutConstraint?
    // 设置 图片高度约束
    var pictureHeightCons: NSLayoutConstraint?
   
    
    //MARK - 界面设置
    override init(style: UITableViewCellStyle,reuseIdentifier: String?){
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupUI()
        
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    // 设置界面
    private func setupUI() {
        
        // 1,添加控件
        contentView.addSubview(topview)
        contentView.addSubview(contentLabel)
        contentView.addSubview(pictureView)
        contentView.addSubview(bottomView)
        // 2，设置布局
        // 1> 顶部视图
        topview.ff_AlignInner(type: ff_AlignType.TopLeft, referView: contentView, size: CGSize(width: UIScreen.mainScreen().bounds.width, height: 53))
        
        // 2> 内容标签
        contentLabel.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: topview, size: nil, offset: CGPoint(x: 8, y: 8))
        // 宽度
        contentView.addConstraint(NSLayoutConstraint(item: contentLabel, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: contentView, attribute: NSLayoutAttribute.Width, multiplier: 1.0, constant: -16))
        /// 配图视图
     let cons = pictureView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: contentLabel, size: CGSize(width: 290, height: 290), offset: CGPoint(x: 0, y: 8))
       pictureWidthCons = pictureView.ff_Constraint(cons , attribute: NSLayoutAttribute.Width)
        pictureHeightCons = pictureView.ff_Constraint(cons, attribute: NSLayoutAttribute.Height)
        
        // 4> 底部视图
        bottomView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: pictureView, size: CGSize(width: UIScreen.mainScreen().bounds.width, height: 44), offset: CGPoint(x: -8, y: 8))
        // 底部约束
//        contentView.addConstraint(NSLayoutConstraint(item: bottomView, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.Equal, toItem: contentView, attribute: NSLayoutAttribute.Bottom, multiplier: 1.0, constant: 0))
    }
  //  MARK :- 懒加载控件
/// 顶部视图
    private lazy var topview: topView = topView()
/// 内容标签
    private lazy var contentLabel: UILabel = {
        let label = UILabel(color: UIColor.darkGrayColor(), fontSize: 15)
        label.numberOfLines = 0
    return label
    }()
 /// 配图视图
    private lazy var pictureView: StatusPictureView = StatusPictureView()
    
/// 底部视图
    private lazy var bottomView: statusBottomView = statusBottomView()
    
}


